<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php include 'logincheck.php'?>
<html>
<head>
<title>Alert subscribers</title>
<?php
include 'head.php';
?>
</head>
<body>
<?php
include 'nav.php';
?>
<div id="wrapper">
<div id="content">
<div class="panel">You are now logged in | <a href="post">New</a> | <a href="edit">Edit</a> | <a href="alert">Alert</a> | <a href="logout">Logout</a></div>
<h1>Send notifications to subscribers</h1>
<form id="postList" action="sendNews.php" method="post">
<table id="alertTable">
	<thead>
    <tr>
      <th style="padding-left:5px;">Posts to send</th>
    </tr>
	</thead>
	<tbody style="width:50%">
<?php
include 'connect.php';
mysql_select_db($db, $con);

$query  = "SELECT * FROM {$table} WHERE isNotified = false ORDER BY ID DESC";
$result = mysql_query($query) or die(mysql_error());
$op = "";

while($row = mysql_fetch_assoc($result)) {
	$url = $row['URL']."_id_".$row['ID'];
	
	$op = $op. "\n<tr><td style='text-align:left'><input type='checkbox' id={$row['ID']}></input> <a href='" . $url."'>".$row['Name']."</a></td></tr>";
}
echo $op;
mysql_close($con);
?>
</tbody>
<tfoot>
<tr><td colspan="2" style="text-align:left;padding:10px;"><input type="submit" style="padding:4px" value="Alert subscribers "></input></td></tr>
</tfoot>
</table>

</form>
<form id="listForm" action="sendNotifMails.php" method="post">
<input type="hidden" name="idList" id="idList" value=""></input>
</form>
</div>
</div>
<?php
include 'footer.php';
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
 /* attach a submit handler to the form */
$("#postList").submit(function(event) {

/* stop form from submitting normally */
event.preventDefault(); 
	
/* get some values from elements on the page: */
var $form = $( this ),
	checkboxes = $("input:checked");
	ids = [];
	$("input:checked").each(function(){ids.push(parseInt($(this).attr('id')))});
	console.log(ids)
	/* Send the data using post and put the results in a div */
	$('#idList').val(ids);
	$('#listForm').submit();
	/*
$.post( url, { text: text, title: title, id: id, cat: cat },
  function( data ) {
	  //var content = $( data ).find( '#content' );
	  $( "#result" ).empty().append( data );
  }
);*/
});
</script>
</body>
</html>